//
//  MBSpaceMyAlbumCell.m
//  MiBaoTu
//
//  Created by admin on 16/9/22.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceMyAlbumCell.h"

@interface MBSpaceMyAlbumCell () {
    UIView                  *_bgView;
    UIImageView             *_nickImgView;
    UILabel                 *_nickNameLb;
    UILabel                 *_musicTypeLb;
    UILabel                 *_contentLb;
    UIView                  *_lineView;
    UIButton                *_contentBt;
}

@end
@implementation MBSpaceMyAlbumCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self onCreateUI];
    }
    return self;
}

- (void)onCreateUI
{
    self.backgroundColor = [UIColor clearColor];
    self.backgroundView = nil;
    
    //背景
    _bgView = [[UIView alloc]initWithFrame:CGRectZero];
    _bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_bgView];
    
    //头像
    _nickImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _nickImgView.backgroundColor = [UIColor clearColor];
    _nickImgView.layer.cornerRadius = 55*PERCEN;
    _nickImgView.layer.masksToBounds = YES;
    [_bgView addSubview:_nickImgView];
    
    //标题
    _nickNameLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _nickNameLb.backgroundColor = [UIColor clearColor];
    _nickNameLb.textAlignment = NSTextAlignmentLeft;
    _nickNameLb.textColor = UIColorFromHex(0x333333);
    _nickNameLb.font = [UIFont systemFontOfSize:13.f];
    [_bgView addSubview:_nickNameLb];
    
    //类型
    _musicTypeLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _musicTypeLb.backgroundColor = [UIColor clearColor];
    _musicTypeLb.textAlignment = NSTextAlignmentLeft;
    _musicTypeLb.textColor = UIColorFromHex(0x9999999);
    _musicTypeLb.font = [UIFont systemFontOfSize:11.f];
    [_bgView addSubview:_musicTypeLb];
    
    //大小
    _contentLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _contentLb.backgroundColor = [UIColor clearColor];
    _contentLb.textAlignment = NSTextAlignmentLeft;
    _contentLb.textColor = UIColorFromHex(0x999999);
    _contentLb.font = [UIFont systemFontOfSize:11.f];
    [_bgView addSubview:_contentLb];
    
//    //下载图标
//    _downImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
//    _downImgView.backgroundColor = [UIColor clearColor];
//    [_contentView addSubview:_downImgView];
    
    _contentBt = [UIButton buttonWithType:UIButtonTypeCustom];
    _contentBt.backgroundColor = [UIColor clearColor];
    [_contentBt setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal];
    [_bgView addSubview:_contentBt];
    
    //线
    _lineView = [[UIView alloc]initWithFrame:CGRectZero];
    _lineView.backgroundColor = [UIColorFromHex(0x999999) colorWithAlphaComponent:.35];
    [_bgView addSubview:_lineView];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setOrientation:(UIDeviceOrientation)orientation
{
    _orientation = orientation;
    [self setNeedsLayout];
}

- (void)setDataDic:(NSDictionary *)dataDic
{
    _dataDic = dataDic;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    /*
     {
     "ID": 1,
     "AlbumName": "lalala",
     "IconPath": "",
     "Synopsis": "",
     "AlbumType": 1,
     "AlbumStatus": 1,
     "CreateTime": 0,
     "CateID": 1,
     "ItemName": "儿歌",
     "ParentID": 0,
     "Seq": 1
     }
     */
    //value
    {
        if(_dataDic.allKeys.count == 0) return;
        if ([_dataDic.allKeys containsObject:@"FaceImg"]) {
            [_nickImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,[_dataDic objectForKey:@"FaceImg"]]] placeholderImage:[UIImage imageNamed:@"album_header_bg"]];
            _nickNameLb.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"NickName"]];
            _musicTypeLb.text = [NSString stringWithFormat:@"共%@首",[_dataDic objectForKey:@"ShowNum"]];
            NSString *ss = [_dataDic objectForKey:@"Signature"];
            if ([ss isKindOfClass:[NSNull class]]) {
                _contentLb.text = @"";
            } else {
                _contentLb.text = [NSString stringWithFormat:@"%@",ss];
            }
        }
        else {
            [_nickImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,[_dataDic objectForKey:@"IconPath"]]] placeholderImage:[UIImage imageNamed:@"album_header_bg"]];
            _nickNameLb.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"AlbumName"]];
            _musicTypeLb.text = [NSString stringWithFormat:@"共%@首",[_dataDic objectForKey:@"AudioNum"]];
            NSString *ss = [_dataDic objectForKey:@"Synopsis"];
            if ([ss isKindOfClass:[NSNull class]]) {
                _contentLb.text = @"";
            } else {
                _contentLb.text = [NSString stringWithFormat:@"%@",ss];
            }
        }
    }
    
    //frame
    _bgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.height);
    _nickImgView.frame = CGRectMake((ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (_bgView.height-110*PERCEN)/2., 110*PERCEN, 110*PERCEN);
    
    _nickNameLb.frame = CGRectMake(_nickImgView.right+20*PERCEN, (WIDTH_5S ? 14*PERCEN : 22*PERCEN), 200, 20);
    
    _musicTypeLb.frame = CGRectMake(_nickNameLb.left, _nickNameLb.bottom-4, _nickNameLb.width, _nickNameLb.height);
    
    _contentBt.frame = CGRectMake(_bgView.width-70*PERCEN-(ISIPAD?440*PERCEN:0), (_bgView.height-50)/2., 70*PERCEN, 50);
    
    _lineView.frame = CGRectMake((ISIPAD?440*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), _bgView.height-1, (ISIPAD?_bgView.width-880*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):_bgView.width), 1);
    _contentLb.frame = CGRectMake(_nickNameLb.left, _musicTypeLb.bottom-4, _contentBt.left-_nickNameLb.left, _nickNameLb.height);
}

@end
